#ifndef DJI_MOTOR_H
#define DJI_MOTOR_H

#include "bsp_can.h"
#include "motor_def.h"
#include "stdint.h"

#define DJI_MOTOR_MAX_NUM 10
#define DJI_ECD_TO_ANGLE  0.0439453125f
typedef struct 
{
    uint16_t ecd;
    uint16_t last_ecd;
    float    single_round_angle;
    float    total_angle;
    float    speed;
    int16_t  current;
    uint8_t  temperature;
    int32_t  total_round;
} DJI_Motor_Measure_s;

typedef struct
{
    DJI_Motor_Measure_s measure;
    Motor_Control_Config_s config;
    Motor_Control_s control;
    CANInstance* motor_can_instance;

    uint8_t group_num;
    uint8_t motor_num;
    
    Motor_Type_e motor_type;
    Motor_Working_Type_e motor_working_type;
    float dt;
} DJIMotorInstance;

DJIMotorInstance* DJIMotorInit(Motor_Init_Config_s* init_config);
void DJIMotorSetRef(DJIMotorInstance* instance, float ref);
void DJIMotorControl(void);
void DJIMotorStop(DJIMotorInstance* motor);
void DJIMotorStart(DJIMotorInstance* motor);
#endif
